package com.base.controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.base.service.ShopOrderService;
import com.base.utils.Page;

/**
 * 购物订单信息服务端
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class index_Order {

	@Autowired
	private ShopOrderService shopOrderService; // 订单信息

	/**
	 * 订单信息
	 * 
	 * @param request       获取参数
	 * @param currentPageNo 当前页
	 * @param mobile        手机号码
	 * @param ordernum      订单编号
	 * @return ModelAndView
	 * @throws Exception
	 */
	@RequestMapping("/orderIndex")
	public ModelAndView orderIndex(HttpServletRequest request, Integer currentPageNo, String mobile, String ordernum)
			throws Exception {
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return new ModelAndView("jsp/loginCheck"); // 未登录
		if ((int) request.getSession().getAttribute("adminUsergrade") == 0) userid = null; // 如果是ADMIN用户就显示全部
		Map<String, Object> map = new HashMap<>(); // 存储数据对象
		// 设置分页 获取内容
		Page page = new Page(); // 实例化分页工具类
		if (currentPageNo != null) page.setCurrentPageNo(currentPageNo); // 设置当前页
		page.setRecordTotal(shopOrderService.countByAll(ordernum, mobile, userid, null, null)); // 总条数
		map.put("sodList", shopOrderService.selectByAll(page, ordernum, mobile, userid, null, null)); // 存储订单对象
		map.put("ordernum", ordernum); // 订单编号
		map.put("mobile", mobile); // 用户手机号码
		map.put("pages", page); // 分页
		return new ModelAndView("jsp/index_Order", map);
	}
}
